///////////////////////////////////////////////////////////////////////////////
//// FileName: iPN_API.h
//// Description: iPN API Header file
//// Author: Leo Yu (yulin724@gmail.com)
//// All right reserved 2014.
////  Revision History:
////      Create Date: 2014/09/18
////
////////////////////////////////////////////////////////////////////////////////

#ifndef IPN_API_H_
#define IPN_API_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#ifdef LINUX
#include <arpa/inet.h>  // inet_ntoa
#include <netdb.h>
#endif //// #ifdef LINUX

#ifdef WIN32DLL
#include <winsock2.h>
#endif  //// #ifdef WIN32DLL
#include <signal.h> // signal
#include <assert.h>


#include "iPN_Error.h"
#include "iPN_Type.h"
#include "SocketAPI.h"
#include "iPN_Debug.h"
#include "iPN_Profile.h"
#include "iPN_Proto.h"
#include "iPN_AuthEnc.h"

#ifdef __cplusplus
extern "C" {
#endif

void iPN_Debug(UINT32 DebugLevel, const CHAR* FilePath);

INT32 iPN_Initialize(const CHAR * InitString, const CHAR* AESKey);

INT32 iPN_DeInitialize();

INT32 iPN_NetworkDetect();

INT32 iPN_ConnectToPortalServer(const CHAR* AESKey, int timeout_Sec);

/*
 * bFlagOpen = true, 该Publish的SubscribeToken 允许 通过QueryToken进行获取，获取密码为QueryTokenPassword
 * bFlagOpen = false, 该Publish的SubscribeToken 不允许 通过QueryToken进行获取
 */
INT32 iPN_Publish(const CHAR *OwnerDID, const CHAR *EventName, const CHAR* AuthCode, const CHAR* AESKey,
		CHAR *PostToken, CHAR * SubscribeToken, int bFlagOpen, CHAR* QueryTokenPassword);

INT32 iPN_UnPublish(const CHAR *OwnerDID, const CHAR *EventName, const CHAR *AuthCode, const CHAR* AESKey);

INT32 iPN_Post(const CHAR *PostToken, const CHAR* AESKey, const time_t TimeStamp, const CHAR* AdditionalInfo);

INT32 iPN_Subscribe_Common(const CHAR *TableName, const CHAR * SubscribeToken, const CHAR* AESKey,
		const CHAR* ToAddress, UINT32 *SubscriberID);

INT32 iPN_UnSubscribe_Common(const CHAR* TableName, const CHAR *SubscribeToken, const CHAR* AESKey,
		UINT32 SubscriberID);

INT32 iPN_Subscribe_DirectPush(const CHAR * SubscribeToken, const CHAR* AESKey, const CHAR* toAddress,
		UINT32 *SubscriberID);

INT32 iPN_UnSubscribe_DirectPush(const CHAR *SubscribeToken, const CHAR* AESKey, UINT32 SubscriberID);

INT32 iPN_Subscribe_Email(const CHAR * SubscribeToken, const CHAR* AESKey, const CHAR* EmailAddress,
		UINT32 *SubscriberID);

INT32 iPN_UnSubscribe_Email(const CHAR *SubscribeToken, const CHAR* AESKey, UINT32 SubscriberID);

INT32 iPN_Subscribe_MQTTMessage(const CHAR * SubscribeToken, const CHAR* AESKey, const CHAR* Topic,
		UINT32 *SubscriberID);

INT32 iPN_UnSubscribe_MQTTMessage(const CHAR *SubscribeToken, const CHAR* AESKey, UINT32 SubscriberID);

INT32 iPN_Subscribe_XinGe(const CHAR * SubscribeToken, const CHAR* AESKey, const CHAR* DeviceToken,
		UINT32 *SubscriberID);

INT32 iPN_UnSubscribe_XinGe(const CHAR *SubscribeToken, const CHAR* AESKey, UINT32 SubscriberID);

INT32 iPN_Subscribe_Uniqush(const CHAR * SubscribeToken, const CHAR* AESKey, const CHAR* DeviceToken,
		UINT32 *SubscriberID);

INT32 iPN_UnSubscribe_Uniqush(const CHAR *SubscribeToken, const CHAR* AESKey, UINT32 SubscriberID);    

INT32 iPN_Subscribe_Voip(const CHAR * SubscribeToken, const CHAR* AESKey, const CHAR* PhoneNo, UINT32 *SubscriberID);

INT32 iPN_UnSubscribe_Voip(const CHAR *SubscribeToken, const CHAR* AESKey, UINT32 SubscriberID);

INT32 iPN_Subscribe_SMS(const CHAR * SubscribeToken, const CHAR* AESKey, const CHAR* PhoneNo, UINT32 *SubscriberID);

INT32 iPN_UnSubscribe_SMS(const CHAR *SubscribeToken, const CHAR* AESKey, UINT32 SubscriberID);

INT32 iPN_QueryToken(const CHAR* OwnerDID, const CHAR* EventName, const CHAR* QueryTokenPassword, CHAR *SubscribeToken,
		const CHAR* AESKey);

INT32 iPN_DirectPush_Wait(const CHAR* srvName, const CHAR* toAddress, CHAR *info, UINT32 timeout_in_sec);

#ifdef __cplusplus
}
#endif

#endif /* IPN_API_H_ */
